import * as echarts from "echarts"
import chinaJson from '../data/china.json'

// 注册中国地铁
echarts.registerMap("china", chinaJson)

function useEcharts(el: HTMLElement) {
  const echartsInstance = echarts.init(el)
  const setOption = (option: echarts.EChartsOption) => {
    echartsInstance.setOption(option)
  }
  const updateSize = () => {
    echartsInstance.resize()
  }
  window.addEventListener("resize", () => {
    echartsInstance.resize()
  })

  return {
    echartsInstance,
    setOption,
    updateSize
  }
}

export default useEcharts